package com.itheima.config;


import org.springframework.web.filter.CharacterEncodingFilter;
import org.springframework.web.servlet.support.AbstractAnnotationConfigDispatcherServletInitializer;

import javax.servlet.Filter;

public class ServletContainerInitConfig extends AbstractAnnotationConfigDispatcherServletInitializer {

    //注册Spring容器
    protected Class<?>[] getRootConfigClasses() {
        return new Class[0];
    }

    //注册SpringMvc容器
    protected Class<?>[] getServletConfigClasses() {
        return new Class[]{SpringMvcConfig.class};
    }

    //规定哪些请求属于SpringMvc
    protected String[] getServletMappings() {
        return new String[]{"/"};
    }

    //乱码处理

    @Override
    protected Filter[] getServletFilters() {

        CharacterEncodingFilter filter = new CharacterEncodingFilter();
        filter.setEncoding("UTF-8");

        return new Filter[]{filter};
    }
}
